function setCookie(name, value, expires) {
    if (expires) {
        var now = new Date();
        now.setDate(now.getDate() + parseInt(expires));
        // toGMTString() 将时间转成格林威治时间
        document.cookie = `${name}=${encodeURIComponent(value)};expires=${now.toGMTString()}`
    } else {
        document.cookie = `${name}=${encodeURIComponent(value)}`
    }
}

function getCookie(key) {
    var arr = document.cookie.split("; ");
    for (let i = 0; i < arr.length; i++) {
        var a = arr[i].split("=");
        if (a[0] == key) {
            return decodeURIComponent(a[1])
        }
    }
}